package com.kawins.mybatis;

import org.apache.commons.lang3.ArrayUtils;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;

import java.io.IOException;

/**
 * @author rankai
 *         createTime 2017-09-2017/9/27 15:42
 */
public class SqlSessionFactoryBean extends org.mybatis.spring.SqlSessionFactoryBean {

    public void setStrMapperLocations(String strMapperLocations) throws IOException {
        Resource[] resourcesAll = new Resource[0];
        String[] split = strMapperLocations.split(",");
        ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
        for (int i = 0; i < split.length; i++) {
            Resource[] resourcesTemp = resolver.getResources(split[i]);
            resourcesAll = ArrayUtils.addAll(resourcesAll, resourcesTemp);
        }
        super.setMapperLocations(resourcesAll);
    }
}
